package org.ermannofranco.genericdaojdbc.user.model;

import net.ermannofranco.genericdaojdbc.model.VersionedEntity;
import net.ermannofranco.genericdaojdbc.model.annotation.ColumnMapping;
import net.ermannofranco.genericdaojdbc.model.annotation.ExcludeFromInsert;
import net.ermannofranco.genericdaojdbc.model.annotation.ForeignEntities;
import net.ermannofranco.genericdaojdbc.model.annotation.IdColumn;
import net.ermannofranco.genericdaojdbc.model.annotation.ManyToOne;
import net.ermannofranco.genericdaojdbc.model.annotation.Tablename;

/**
 * Nostro oggetto di domain
 * 
 * @author ermanno (ermanno.franco@gmail.com)
 * 
 */
@Tablename("UTENTI")
@ExcludeFromInsert("version")
@ForeignEntities(manyToOne = @ManyToOne(column = "ADDRESS_ID", entityClass = Address.class, property = "address", daoBeanId = "addressDao"))
@IdColumn(column = "USER_ID", generated = true)
@ColumnMapping(column = "TIPO_UTENTE", property = "tipoUtente")
public class User extends VersionedEntity<Long> {

	private static final long serialVersionUID = -4735947006429455802L;
	private static final int DEFAULT_ETA = 30;
	private static final int DEFAULT_TIPO_UTENTE = 1;
	private int etaaaa;
	private String nnnnome;
	private String loggggin;
	private String pasSWWWword;
	private int segnapostoPerTipoUt;
	private String em______ail;

	private Address address;

	public User() {
		etaaaa = DEFAULT_ETA;
		segnapostoPerTipoUt = DEFAULT_TIPO_UTENTE;
	}

	public User(int eta, String nome, String login, String password,
			int tipoUtente, int version) {
		this.etaaaa = eta;
		this.nnnnome = nome;
		this.loggggin = login;
		this.pasSWWWword = password;
		this.segnapostoPerTipoUt = tipoUtente;
		setVersion(version);
	}

	public int getEta() {
		return etaaaa;
	}

	public String getNome() {
		return nnnnome;
	}

	public String getLogin() {
		return loggggin;
	}

	public String getPassword() {
		return pasSWWWword;
	}

	public int getTipoUtente() {
		return segnapostoPerTipoUt;
	}

	public void setEta(int i) {
		etaaaa = i;

	}

	public void setNome(String nome) {
		this.nnnnome = nome;
	}

	public void setLogin(String login) {
		if (login == null || login.trim().length() == 0)
			login = null;
		this.loggggin = login;
	}

	public void setPassword(String password) {
		this.pasSWWWword = password;
	}

	public void setTipoUtente(int tipoUtente) {
		this.segnapostoPerTipoUt = tipoUtente;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(" nome: ").append(nnnnome).append(" id: ").append(getId()).append(" - login: ")
				.append(loggggin).append(" - tipo utente: ").append(
						segnapostoPerTipoUt).append(" - version: ").append(
						getVersion()).append(" - eta': ").append(etaaaa).append(" - email: ").append(em______ail);
		return sb.toString();
	}

	public String getEmail() {
		return em______ail;
	}

	public void setEmail(String email) {
		this.em______ail = email;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

}
